package club.janna.jrpc.cluster.loadbalance;

import club.janna.jrpc.annotation.SPIService;
import club.janna.jrpc.cluster.loadbalance.selector.RandomSelector;
import club.janna.jrpc.cluster.loadbalance.selector.Selector;
import club.janna.jrpc.cluster.loadbalance.selector.SingleSelector;
import club.janna.jrpc.rpc.Invoker;

/**
 * 随机负载均衡器
 * @author Panbo.Guo
 */
@SPIService("random")
public class RandomLoadBalancer extends AbstractLoadBalancer {
    @Override
    protected Selector buildSelector(Invoker[] invokers) {
        int n = invokers.length;
        return n == 0 ? new SingleSelector() : new RandomSelector(n);
    }
}
